/**
 * 表单验证
 * 
 * @param {Object} rules 验证字段的规则
 * @param {Object} messages 验证字段的提示信息
 * 
 */
import basic from './basic.js';
var actmodel = new basic();
actmodel.do = "sys_data"

// actmodel.gettips

actmodel.gettips = function () {
  var app = getApp();
 
  var data = { op:'gettips' } 
  return new Promise((resolve, reject) => {
    // if(app.globalData.sysdata["citys"]){
    //   resolve({status:1,obj:app.globalData.sysdata["citys"]});
    // }

    app.util.request({
      'url': 'entry/wxapp/' + actmodel.do,
      'data': data,
      'method': "get",
      showLoading: false,
      success: function (res) {
        if (res.data.errno == 0) {

          var data= res.data.data;
          // if(data.status==1){
          //   data["obj"] =  JSON.parse(data["obj"])  
          //   app.globalData.sysdata["citys"]=data["obj"];
          // }
                     
          resolve(data);
        }
        reject(res.data.message);
      },
      fail: function (res) {
        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      },
      complete: function () {
      }
    });
  });
} 

actmodel.citys = function () {
  var app = getApp();
 
  var data = { op:'citys' } 
  return new Promise((resolve, reject) => {
    if(app.globalData.sysdata["citys"]){
      resolve({status:1,obj:app.globalData.sysdata["citys"]});
    }

    app.util.request({
      'url': 'entry/wxapp/' + actmodel.do,
      'data': data,
      'method': "get",
      showLoading: false,
      success: function (res) {
        if (res.data.errno == 0) {

          var data= res.data.data;
          if(data.status==1){
            data["obj"] =  JSON.parse(data["obj"])  
            app.globalData.sysdata["citys"]=data["obj"];
          }
                     
          resolve(data);
        }
        reject(res.data.message);
      },
      fail: function (res) {
        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      },
      complete: function () {
      }
    });
  });
} 

actmodel.offset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["modifytime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/" + actmodel.do;
  if (para) {
    para["op"] = "offset"
  }
  else {
    this.wherepara["op"] = "offset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}


module.exports = actmodel;